﻿@namespace Masa.Blazor.Docs.Components
@inherits NextTickComponentBase

@if (_rendered)
{
    if (_type == null)
    {
        <MAlert Type="AlertTypes.Error" Outlined>
            The file "@File" doesn't exist.
        </MAlert>
    }
    else
    {
        <MSheet Class="m-example"
                Outlined
                Rounded="true">
            <div style="min-height: 52px">
                <MSheet Class="pa-4" Rounded="true" Dark="_dark">
                    @if (_type is not null)
                    {
                        <DynamicComponent Type="_type"></DynamicComponent>
                    }
                </MSheet>

                @if (!NoActions)
                {
                    <AppDivider />

                    <div class="text-end pa-2">
                        @foreach (var tooltip in _tooltips)
                        {
                            <AppTooltipButton Icon="@tooltip.Icon"
                                              Path="@tooltip.Path"
                                              Href="@tooltip.href"
                                              Target="@(tooltip.href != null ? "_blank" : null)"
                                              Class="mx-2"
                                              OnClick="() => tooltip.OnClick?.Invoke()" />
                        }
                    </div>

                    @if (_showExpands)
                    {
                        <AppDivider />

                        <ExpandTransition>
                            <ShowTransitionElement Value="_expand">
                                <MItemGroup @bind-Value="_selected" Class="pa-2" Mandatory>
                                    @foreach (var item in _sections)
                                    {
                                        <MItem>
                                            <MButton Class="mr-2"
                                                     IsActive="@context.Active"
                                                     Text
                                                     Color="primary"
                                                     OnClick="@context.Toggle">
                                                @item.Language
                                            </MButton>
                                        </MItem>
                                    }
                                </MItemGroup>

                                <AppDivider />

                                <MWindow Value="_selected" Class="grey lighten-5 rounded-b">
                                    @foreach (var item in _sections)
                                    {
                                        <MWindowItem>
                                            <Markup Code="@item.Code" Language="@item.Language" Rounded="false" />
                                        </MWindowItem>
                                    }
                                </MWindow>
                            </ShowTransitionElement>
                        </ExpandTransition>
                    }
                }
            </div>
        </MSheet>
    }
}
else
{
    <MSkeletonLoader MinHeight="250" MaxHeight="250" Type="card"></MSkeletonLoader>
}
